package com.xj.demo.reference;

import java.lang.ref.WeakReference;

public class WeakObjTest {
    static class User{
        private String name;
        private int age;
        public User(String name, int age) {
            this.name = name;
            this.age = age;
        }
        @Override
        public String toString() {
            return "User{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }
    public static void main(String[] args) {
        WeakReference<User> wr = new WeakReference<>(new User("xj", 18));
        System.out.println("Before GC" + wr.get());
        System.gc();
        System.out.println("After GC:" + wr.get());
    }
}
